home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_kdelibs.idb / usr / freeware / kde / include / htmlform.h.z / htmlform.h
Encoding:
C/C++ Source or Header  |  1999-01-26  |  8.0 KB  |  379 lines

  1. /* This file is part of the KDE libraries
  2.     Copyright (C) 1997 Martin Jones (mjones@kde.org)
  3.               (C) 1997 Torben Weis (weis@kde.org)
  4.  
  5.     This library is free software; you can redistribute it and/or
  6.     modify it under the terms of the GNU Library General Public
  7.     License as published by the Free Software Foundation; either
  8.     version 2 of the License, or (at your option) any later version.
  9.  
  10.     This library is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.     Library General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU Library General Public License
  16.     along with this library; see the file COPYING.LIB.  If not, write to
  17.     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  18.     Boston, MA 02111-1307, USA.
  19. */
  20. //----------------------------------------------------------------------------
  21. // khtml widget - forms
  22. //
  23. //
  24.  
  25. #ifndef __HTMLFORM_H__
  26. #define __HTMLFORM_H__
  27.  
  28. class HTMLElement;
  29. class HTMLForm;
  30. class HTMLSelect;
  31. class HTMLButton;
  32. class HTMLTextArea;
  33.  
  34. #include <qwidget.h>
  35.  
  36. #include "htmlobj.h"
  37.  
  38. class HTMLForm;
  39.  
  40. //---------------------------------------------------------------------------
  41.  
  42. class HTMLElement
  43. {
  44. public:
  45.     HTMLElement( const char *n )
  46.         { _name = n; form = 0; }
  47.     virtual ~HTMLElement();
  48.  
  49.     const QString &elementName() const
  50.         {    return _name; }
  51.     void setElementName( const char *n )
  52.         {    _name = n; }
  53.  
  54.     void setForm( HTMLForm *f )
  55.         {    form = f; }
  56.  
  57.     // This function places the element on the page using the
  58.     // absolute coordinates.  Also responsible for showing/hiding
  59.     // non-visible elements
  60.     virtual void position( int /*_x*/, int /*_y*/,
  61.                    int /*_width*/, int /*_height*/ ) {}
  62.  
  63.     virtual QString encoding()
  64.         {    return QString( "" ); }
  65.  
  66.     virtual void calcAbsolutePos( int , int ) {}
  67.  
  68.     virtual void reset() { }
  69.  
  70. protected:
  71.     // encode special characters
  72.     QString encodeString( const QString &e );
  73.  
  74. protected:
  75.     QString _encoding;
  76.  
  77. private:
  78.     QString _name;
  79.  
  80.     HTMLForm *form;
  81. };
  82.  
  83. class HTMLWidgetElement : public QObject, public HTMLObject, public HTMLElement
  84. {
  85.     Q_OBJECT
  86. public:
  87.     HTMLWidgetElement( const char *n ) : HTMLElement( n )
  88.         { _absX = 0; _absY = 0; widget = 0; }
  89.     virtual ~HTMLWidgetElement();
  90.  
  91.     int absX() const
  92.         {    return _absX; }
  93.     int absY() const
  94.         {    return _absY; }
  95.  
  96.     // This function places the element on the page using the
  97.     // absolute coordinates.  Also responsible for showing/hiding
  98.     // non-visible elements
  99.     virtual void position( int _x, int _y, int _width, int _height );
  100.  
  101.     virtual void calcAbsolutePos( int _x, int _y );
  102.  
  103. protected:
  104.     QWidget *widget;
  105.  
  106. private:
  107.     // absolute position of this element in the page
  108.     int _absX;
  109.     int _absY;
  110. };
  111.  
  112. //---------------------------------------------------------------------------
  113.  
  114. class HTMLSelect : public HTMLWidgetElement
  115. {
  116.     Q_OBJECT
  117. public:
  118.     HTMLSelect( QWidget *parent, const char *n, int s, bool m );
  119.     virtual ~HTMLSelect() { }
  120.  
  121.     void addOption( const char *o, bool sel );
  122.  
  123.     // set text for current option
  124.     void setText( const char *text );
  125.  
  126.     const QString &value()
  127.         {    return *_values.at( _item ); }
  128.     const QString &value( int item );
  129.     void setValue( const char *v, int item );
  130.  
  131.     virtual QString encoding();
  132.     virtual void reset();
  133.  
  134. protected slots:
  135.     void slotHighlighted( int indx );
  136.  
  137. private:
  138.     int _defSelected;
  139.     int _size;
  140.     QList<QString> _values;
  141.     int _item;
  142. };
  143.  
  144. //---------------------------------------------------------------------------
  145.  
  146. class HTMLTextArea : public HTMLWidgetElement
  147. {
  148.     Q_OBJECT
  149. public:
  150.     HTMLTextArea( QWidget *parent, const char *n, int r, int c );
  151.     virtual ~HTMLTextArea() { }
  152.  
  153.     QString value();
  154.     void setText( const char *t );
  155.  
  156.     virtual QString encoding();
  157.     virtual void reset();
  158.  
  159. private:
  160.     QString _defText;
  161. };
  162.  
  163. //---------------------------------------------------------------------------
  164.  
  165. class HTMLInput : public HTMLWidgetElement
  166. {
  167.     Q_OBJECT
  168. public:
  169.     HTMLInput( const char *n, const char *v );
  170.     virtual ~HTMLInput() { }
  171.  
  172.     const QString &value() const
  173.         {    return _value; }
  174.     void setValue( const char *v )
  175.         {    _value = v; }
  176.  
  177. private:
  178.     QString   _value;
  179. };
  180.  
  181. //---------------------------------------------------------------------------
  182.  
  183. class HTMLCheckBox : public HTMLInput
  184. {
  185.     Q_OBJECT
  186. public:
  187.     HTMLCheckBox( QWidget *parent, const char *n, const char *v, bool ch );
  188.     virtual ~HTMLCheckBox() { }
  189.  
  190.     virtual QString encoding();
  191.     virtual void reset();
  192.  
  193. private:
  194.     bool _defCheck;
  195. };
  196.  
  197. //---------------------------------------------------------------------------
  198.  
  199. class HTMLHidden : public HTMLInput
  200. {
  201.     Q_OBJECT
  202. public:
  203.     HTMLHidden( const char *n, const char *v );
  204.     virtual ~HTMLHidden() { }
  205.  
  206.     virtual QString encoding();
  207. };
  208.  
  209. //---------------------------------------------------------------------------
  210.  
  211. class HTMLRadio : public HTMLInput
  212. {
  213.     Q_OBJECT
  214. public:
  215.     HTMLRadio( QWidget *parent, const char *n, const char *v, bool ch );
  216.     virtual ~HTMLRadio() { }
  217.  
  218.     virtual QString encoding();
  219.     virtual void reset();
  220.  
  221. public slots:
  222.     void slotRadioSelected( const char *n, const char *v );
  223.  
  224. signals:
  225.     void radioSelected( const char *n, const char *v );
  226.  
  227. protected slots:
  228.     void slotClicked();
  229.  
  230. private:
  231.     bool _defCheck;
  232. };
  233.  
  234. //---------------------------------------------------------------------------
  235.  
  236. class HTMLReset : public HTMLInput
  237. {
  238.     Q_OBJECT
  239. public:
  240.     HTMLReset( QWidget *parent, const char *v );
  241.     virtual ~HTMLReset() { }
  242.  
  243. protected slots:
  244.     void slotClicked();
  245.  
  246. signals:
  247.     void resetForm();
  248. };
  249.  
  250. //---------------------------------------------------------------------------
  251.  
  252. class HTMLSubmit : public HTMLInput
  253. {
  254.     Q_OBJECT
  255. public:
  256.     HTMLSubmit( QWidget *parent, const char *n, const char *v );
  257.     virtual ~HTMLSubmit() { }
  258.  
  259.     virtual QString encoding();
  260.  
  261. protected slots:
  262.     void slotClicked();
  263.  
  264. signals:
  265.     void submitForm();
  266.  
  267. private:
  268.     bool activated;
  269. };
  270.  
  271. //---------------------------------------------------------------------------
  272.  
  273. class HTMLTextInput : public HTMLInput
  274. {
  275.     Q_OBJECT
  276. public:
  277.     HTMLTextInput( QWidget *parent, const char *n, const char *v, int s,
  278.             int ml, bool password = false );
  279.     virtual ~HTMLTextInput() { }
  280.  
  281.     virtual QString encoding();
  282.     virtual void reset();
  283.  
  284. protected slots:
  285.     void slotTextChanged( const char * );
  286.     void slotReturnPressed();
  287.  
  288. signals:
  289.     void submitForm();
  290.  
  291. private:
  292.     QString _defText;
  293. };
  294.  
  295. //---------------------------------------------------------------------------
  296.  
  297. class HTMLImageInput : public HTMLImage, public HTMLElement
  298. {
  299.     Q_OBJECT
  300. public:
  301.     HTMLImageInput( KHTMLWidget *widget, const char *, int mw, const char *n );
  302.     virtual ~HTMLImageInput() {}
  303.  
  304.     virtual QString encoding();
  305.  
  306.     virtual HTMLObject *mouseEvent( int, int, int, int );
  307.  
  308. signals:
  309.     void submitForm();
  310.  
  311. private:
  312.     int  _xp;
  313.     int  _yp;
  314.     bool pressed;
  315.     bool activated;
  316. };
  317.  
  318. //---------------------------------------------------------------------------
  319.  
  320. class HTMLForm : public QObject
  321. {
  322.     Q_OBJECT
  323. public:
  324.     HTMLForm( const char *a, const char *m );
  325.     virtual ~HTMLForm();
  326.  
  327.     void addElement( HTMLElement *e );
  328.     // We keep hidden elements here, not in HTMLObject hierarchy
  329.     void addHidden( HTMLHidden *he );
  330.     void removeElement( HTMLElement *e );
  331.  
  332.     const char *method() const
  333.         {    return _method; }
  334.     const char *action() const
  335.         {    return _action; }
  336.  
  337.     void position( int _x, int _y, int _width, int _height );
  338.  
  339. public slots:
  340.     void slotReset();
  341.     void slotSubmit();
  342.     void slotRadioSelected( const char *n, const char *v );
  343.  
  344. signals:
  345.     void submitted( const char *method, const char *url, const char *data );
  346.     void radioSelected( const char *n, const char *v );
  347.  
  348. private:
  349.     QString _method;
  350.     QString _action;
  351.  
  352.     QList<HTMLElement> elements;
  353.     QList<HTMLHidden>  hidden;
  354. };
  355.  
  356. //---------------------------------------------------------------------------
  357.  
  358. #include "jscript.h"
  359.  
  360. //---------------------------------------------------------------------------
  361.  
  362. class HTMLButton : public HTMLInput
  363. {
  364.     Q_OBJECT
  365. public:
  366.     HTMLButton( KHTMLWidget *_parent, const char *_name, const char *v, QList<JSEventHandler> *_handlers );
  367.     virtual ~HTMLButton();
  368.     
  369. protected slots:
  370.     void slotClicked();
  371.     
  372. protected:
  373.     KHTMLWidget *view;
  374.     QList<JSEventHandler> *eventHandlers;
  375. };
  376.  
  377. #endif
  378.  
  379.